import { ElMessage, ElLoading } from 'element-plus'

export function useMessage() {
    let loading: any = null;

    return {
        success(message) {
            ElMessage({
                type: 'success',
                message,
            })
        },
        warning(message) {
            ElMessage({
                type: 'warning',
                message
            })
        },
        info(message) {
            ElMessage({
                type: 'info',
                message
            })
        },
        error(message) {
            ElMessage({
                type: 'error',
                message
            })
        },
        pageLoadingStart({ text = 'Loading' } = {}) {
            loading = ElLoading.service({
                lock: true,
                text,
                background: 'rgba(0, 0, 0, 0.5)',
            })
        },
        pageLoadingEnd() {
            loading.close()
        }
    }
}